package test1.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import test1.entity.Account;

import java.util.List;

/**
 * @author: mornd
 * @dateTime: 2023/5/15 - 20:21
 */
@Mapper
public interface AccountMapper {

    @Select("select * from account")
    List<Account> list();

    /*
    for update 添加排他锁，当前查询所在的事务未提交时，其它事务不可操作该行数据，阻塞
     */
    @Select("select * from account where accountNo=#{no} for update")
    Account getById(@Param("no") int no);

    @Update("update account set balance=balance+#{money} where accountNo=#{accountNo}")
    int update(@Param("accountNo") int accountNo, @Param("money") double moeny);
}
